const app = getApp(),url = app.globalData.url;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    readOnly: false, // 企业查看时，只读
    positionId: '', // 在企业中心查看应聘者简历时有值
    userUid: '',
    header_img:'',//用户头像
    header:'',//上传头像
    name:'',//用户姓名
    status_title:'在职',//求职状态
    experience:'5年工作经验',//工作经验
    age:'30',//年龄
    education:'本科',//学历
    phone:'',//电话
    email:'',//邮箱
    sansan:[
      {id:1,name:'正在找工作'},{id:2,name:'正在观望'},{id:3,name:'不想换工作'}
    ],
    job_wanted_list:[],//求职意向

    work_list:[],//工作经历

    project_list:[
      {
        'name':'海淀-窗通',//项目司名
        'time':'2017.09-2019.10',//项目时间
        'describe':'为了提高北京市海淀区行政服务审批大厅办事为了提高北京市海淀区行政服务审批大厅办事为了提高北京提高北京了'//描述
      }
    ],//项目经历
    
    education_list:[],//教育经历
    major_list:[],//专业技能
    skill:[
      {id:3,'name':'一般'},
      {id:2,'name':'熟练'},
      {id:1,'name':'精通'},
    ],
    certificate_list:[],//获得证书

    resume_list:[
      {
        'name':'优秀团员.pdf',//简历名
      }
    ],//简历信息
    evaluate:'自我评价',//自我评价
    ttff:false,
  },
  onLoad(options){
    this.setData({
      readOnly: options.type === 'view',
      userUid: options.uid,
      positionId: options.pid
    })
  },
  onShow: function (options) {
    var that = this
    let userUid = ''
    if(this.data.readOnly){
      userUid = this.data.userUid
      that.setData({header_img: wx.getStorageSync('jl_header')})
    } else {
      var userInfo = wx.getStorageSync('userInfo')
      that.setData({header_img:userInfo.avatarUrl})
      userUid = wx.getStorageSync('user_massage').userUid
    }
    var sansan = that.data.sansan
    // 根据用户UID获取简历基本信息详情
    wx.request({
      url: url + 'cvBaseInfo/getCVBaseInfoByUserUid?user_uid='+ userUid,
      method: "GET",
      // data:{user_uid: userUid },
      success:function(res){
        console.log("根据用户UID获取简历基本信息详情",res);
        var ret = res.data
        if(ret.code != 200){
          wx.showToast({
            title: ret.msg,
            icon:'none'
          })
          return
        }
        if(!ret.data) return
        for(let i in sansan){
          if(sansan[i].id == ret.data.findJobStatus){
            var status = sansan[i].name
            break;
          }
        }
        that.setData({
          id:ret.data.id,
          header:ret.data.header,//用户头像
          name:ret.data.name,//用户姓名
          status_title:status || '',//求职状态
          // experience:ret.data.experience,//工作经验
          birthday:ret.data.birthday || '',//年龄
          education:ret.data.education || '',//学历
          phone:ret.data.mobileNo || '',//电话
          email:ret.data.email || '',//邮箱
          introduction:ret.data.introduction,
        })
        
      }
    })
    // 、、求职意向列表
    wx.request({
      url:url+'cvJobIntention/getJobIntent',
      method: "GET",
      data:{
        user_uid: userUid
      },
      success:function(res){
        console.log("...求职意向列表",res);
        var ret = res.data
        if(ret.code == 200){
          that.setData({
            options:ret.data,
            job_wanted_list:ret.data
          })
        }else{
          wx.showToast({
            title: ret.msg,
            icon:'none'
          })
        }
      }
    })
    // 获取工作经历列表
    wx.request({
      url: url + 'cvExperience/getExperienceList',
      method: "GET",
      data:{user_uid: userUid },
      success:function(res){
        // console.log("获取工作经历列表",res);
        var ret = res.data
        if(ret.code == 200){
          that.setData({work_list:ret.data})
        }else{
          
          that.setData({sub:true})
          wx.showToast({
            title: ret.msg,
            icon:'none'
          })
        }
      }
    })
    // 教育经历列表
    wx.request({
      url: url + 'cvEduction/getEducationList',
      method: "GET",
      data:{user_uid: userUid },
      success:function(res){
        console.log("教育经历列表",res);
        var ret = res.data
        if(ret.code == 200){
          that.setData({education_list:ret.data})
        }else{
          
          that.setData({sub:true})
          wx.showToast({
            title: ret.msg,
            icon:'none'
          })
        }
      }
    })
    // 技能列表
    wx.request({
      url: url + 'cvSkill/getSkillList',
      method: "GET",
      data:{user_uid: userUid },
      success:function(res){
        console.log("技能列表",res);
        var ret = res.data
        if(ret.code == 200){
          that.setData({major_list:ret.data})
        }else{
          
          that.setData({sub:true})
          wx.showToast({
            title: ret.msg,
            icon:'none'
          })
        }
      }
    })
    // 证书
    wx.request({
      url: url + 'cvCertification/getCertificateList',
      method: "GET",
      data:{user_uid: userUid },
      success:function(res){
        // console.log("zhegnshu 列表",res);
        var ret = res.data
        if(ret.code == 200){
          that.setData({certificate_list:ret.data})
        }else{
          
          that.setData({sub:true})
          wx.showToast({
            title: ret.msg,
            icon:'none'
          })
        }
      }
    })
    // 项目敬仰
    wx.request({
      url: url + 'cvProjectExperience/getCVProjectExperienceList',
      method: "GET",
      data:{user_uid: userUid },
      success:function(res){
        console.log("项目敬仰 列表",res);
        var ret = res.data
        if(ret.code == 200){
          that.setData({listxiangmu:ret.data})
        }else{
          that.setData({sub:true})
          wx.showToast({
            title: ret.msg,
            icon:'none'
          })
        }
      }
    })
    // 在校情况
    wx.request({
      url: url + 'cvSchoolPosition/getSchoolPositionList',
      method: "GET",
      data:{user_uid: userUid },
      success:function(res){
        console.log("在校情况 列表",res);
        var ret = res.data
        if(ret.code == 200){
          that.setData({listschool:ret.data})
        }else{
          that.setData({sub:true})
          wx.showToast({
            title: ret.msg,
            icon:'none'
          })
        }
      }
    })
    //在校荣誉
    wx.request({
      url: url + 'cvSchoolHonor/getSchoolHonorList',
      method: "GET",
      data:{user_uid: userUid },
      success:function(res){
        console.log("在校荣誉 列表",res);
        var ret = res.data
        if(ret.code == 200){
          that.setData({listrongyu:ret.data})
        }else{
          that.setData({sub:true})
          wx.showToast({
            title: ret.msg,
            icon:'none'
          })
        }
      }
    })
    //培训经历
    wx.request({
      url: url + 'cvTraning/getTrainingList',
      method: "GET",
      data:{user_uid: userUid },
      success:function(res){
        console.log("培训经历 列表",res);
        var ret = res.data
        if(ret.code == 200){
          that.setData({pxlist:ret.data})
        }else{
          that.setData({sub:true})
          wx.showToast({
            title: ret.msg,
            icon:'none'
          })
        }
      }
    })
    //简历
    wx.request({
      url:url+ 'cvFile/getCVFile',
      method: "GET",
      data:{user_uid: userUid},
      success:function(res){
        console.log('简历',res)
        var ret = res.data
        if(ret.code == 200){
          that.setData({
            ttff:true,
            id:ret.data.id,
            fileSize:ret.data.fileSize,
            cvSuffix:ret.data.cvSuffix,
            cvFileName:ret.data.cvFileName,
            fileUrl:ret.data.fileUrl,
          })
        }else{
          
          that.setData({ttff:false})
          // wx.showToast({
          //   title: '您还未上传简历附件',
          //   icon:'none'
          // })
        }
      }
    })
  },
  // 简历个人信息
  bianji(e){
    if(this.data.readOnly) return
    var id =e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/HomePage/myinfo/myinfo?id=' +id,
    })
  },
  // 意向管理
  yxguanli(){
    wx.navigateTo({
      url: '/HomePage/yx_list/yx_list',
    })
    // 
  },
  // 去添加工作经历 修改
  to_add_work(e){
    // return false
    if(this.data.readOnly) return
    var id =e.currentTarget.dataset.id
    wx.navigateTo({
         url: '/HomePage/linejianli/addWork/index?id=' +id
    })
  },
  // 添加证书
  add_zhengshu(e){
    // return false
    if(this.data.readOnly) return
    var id =e.currentTarget.dataset.id
    wx.navigateTo({
         url: '/HomePage/linejianli/zhengshu/index?id=' +id
    })
  },
  //添加技能 编辑技能
  to_add_jineng(e){
    if(this.data.readOnly) return
    var id =e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/HomePage/linejianli/addJineng/index?id=' +id
    })
  },
  my_pingjia(e){
    if(this.data.readOnly) return
    var id =e.currentTarget.dataset.id
    wx.navigateTo({
    //    url: '/HomePage/myinfo/myinfo?id='+id
       url: '/HomePage/linejianli/mypj/index?id='+id
    })
  },
  //项目经历
  to_add_project(e){
    if(this.data.readOnly) return
    var id =e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/HomePage/linejianli/addProject/index?id='+id
    })
  },
  to_add_school(e){
    if(this.data.readOnly) return
    var id =e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/HomePage/linejianli/school/school?id='+id
    })
  },
  // 荣誉
  to_add_rongyu(e){
    if(this.data.readOnly) return
    var id =e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/HomePage/linejianli/rongyu/rongyu?id='+id
    })
  },
  // 培训经历
  to_add_px(e){
    if(this.data.readOnly) return
    var id =e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/HomePage/linejianli/px/px?id='+id
    })
  },
  // 添加学历
  to_add_study(e){
    if(this.data.readOnly) return
    var id =e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/HomePage/linejianli/addStudy/index?id=' +id
    })
  },
  add_pdf(){
    if(this.data.readOnly) return
    wx.navigateTo({
      url: '/HomePage/linejianli/pdf/index'
    })
  },
  fujian(){
    wx.navigateTo({
      url: '/HomePage/jianlifujian/jianlifujian?type=view&uid='+this.data.userUid
    })
  },
  onFloatBtnClick(e){
    let { state } = e.currentTarget.dataset
    this.updateApplyState(state)
  },
  updateApplyState(state){
    let params = {
      applyPositionId: this.data.positionId, 
      applyState: state // 1查看 2感兴趣 3不感兴趣 4邀面试 5待查阅
    }
    wx.request({
      url: url+ 'applyCVManagement/getUpdatePositionApplyState',
      method: "POST",
      header:{ 'Content-Type': 'application/json',},
      data: params,
      success(res){
        if(res.data.code === 200){
          wx.showToast({
            title: '操作成功',
            icon:'success'
          })
          return
        }
        wx.showToast({
          title: res.data.msg || '操作失败',
          icon: 'none'
        })
      },
      fail(err){
        wx.showToast({
          title: '操作失败',
          icon:'none'
        })
      }
    })
  }
})